.\" Man page generated from reStructuredText.
.
.TH "GAMMU-SMSD-SQL" "7" "Oct 03, 2020" "1.42.0" "Gammu"
.SH NAME
gammu-smsd-sql \- gammu-smsd(1) backend using SQL abstraction layer to use any supported database as a message storage
.
.nr rst2man-indent-level 0
.
.de1 rstReportMargin
\\$1 \\n[an-margin]
level \\n[rst2man-indent-level]
level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
-
\\n[rst2man-indent0]
\\n[rst2man-indent1]
\\n[rst2man-indent2]
..
.de1 INDENT
.\" .rstReportMargin pre:
. RS \\$1
. nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin]
. nr rst2man-indent-level +1
.\" .rstReportMargin post:
..
.de UNINDENT
. RE
.\" indent \\n[an-margin]
.\" old: \\n[rst2man-indent\\n[rst2man-indent-level]]
.nr rst2man-indent-level -1
.\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
.in \\n[rst2man-indent\\n[rst2man-indent-level]]u
..
.SH DESCRIPTION
.sp
SQL service stores all its data in database. It can use one of these SQL backends
(configuration option \fBDriver\fP in smsd section):
.INDENT 0.0
.IP \(bu 2
\fBnative_mysql\fP for gammu\-smsd\-mysql
.IP \(bu 2
\fBnative_pgsql\fP for gammu\-smsd\-pgsql
.IP \(bu 2
\fBodbc\fP for gammu\-smsd\-odbc
.IP \(bu 2
.INDENT 2.0
.TP
.B drivers supported by DBI for gammu\-smsd\-dbi, which include:
.INDENT 7.0
.IP \(bu 2
\fBsqlite3\fP \- for SQLite 3
.IP \(bu 2
\fBmysql\fP \- for MySQL
.IP \(bu 2
\fBpgsql\fP \- for PostgeSQL
.IP \(bu 2
\fBfreetds\fP \- for MS SQL Server or Sybase
.UNINDENT
.UNINDENT
.UNINDENT
.SH SQL CONNECTION PARAMETERS
.sp
Common for all backends:
.INDENT 0.0
.IP \(bu 2
\fBUser\fP \- user connecting to database
.IP \(bu 2
\fBPassword\fP \- password for connecting to database
.IP \(bu 2
\fBHost\fP \- database host or data source name
.IP \(bu 2
\fBDatabase\fP \- database name
.IP \(bu 2
\fBDriver\fP \- \fBnative_mysql\fP, \fBnative_pgsql\fP, \fBodbc\fP or DBI one
.IP \(bu 2
\fBSQL\fP \- SQL dialect to use
.UNINDENT
.sp
Specific for DBI:
.INDENT 0.0
.IP \(bu 2
\fBDriversPath\fP \- path to DBI drivers
.IP \(bu 2
\fBDBDir\fP \- sqlite/sqlite3 directory with database
.UNINDENT
.sp
\fBSEE ALSO:\fP
.INDENT 0.0
.INDENT 3.5
The variables are fully described in gammurc documentation.
.UNINDENT
.UNINDENT
.SH TABLES
.sp
New in version 1.37.1.

.sp
You can customize name of all tables in the \fB[tables]\fP\&. The SQL
queries will reflect this, so it\(aqs enough to change table name in this section.
.INDENT 0.0
.TP
.B gammu
Name of the gammu\-table table.
.UNINDENT
.INDENT 0.0
.TP
.B inbox
Name of the inbox table.
.UNINDENT
.INDENT 0.0
.TP
.B sentitems
Name of the sentitems table.
.UNINDENT
.INDENT 0.0
.TP
.B outbox
Name of the outbox table.
.UNINDENT
.INDENT 0.0
.TP
.B outbox_multipart
Name of the outbox_multipart table.
.UNINDENT
.INDENT 0.0
.TP
.B phones
Name of the phones table.
.UNINDENT
.sp
You can change any table name using these:
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
[tables]
inbox = special_inbox
.ft P
.fi
.UNINDENT
.UNINDENT
.SH SQL QUERIES
.sp
Almost all queries are configurable. You can edit them in
\fB[sql]\fP section. There are several variables used in SQL
queries. We can separate them into three groups:
.INDENT 0.0
.IP \(bu 2
phone specific, which can be used in every query, see \fI\%Phone Specific Parameters\fP
.IP \(bu 2
SMS specific, which can be used in queries which works with SMS messages, see \fI\%SMS Specific Parameters\fP
.IP \(bu 2
query specific, which are numeric and are specific only for given query (or set of queries), see \fI\%Configurable queries\fP
.UNINDENT
.SS Phone Specific Parameters
.INDENT 0.0
.TP
.B \fB%I\fP
IMEI of phone
.TP
.B \fB%S\fP
SIM IMSI
.TP
.B \fB%P\fP
PHONE ID (hostname)
.TP
.B \fB%N\fP
client name (eg. Gammu 1.12.3)
.TP
.B \fB%O\fP
network code
.TP
.B \fB%M\fP
network name
.UNINDENT
.SS SMS Specific Parameters
.INDENT 0.0
.TP
.B \fB%R\fP
remote number [1]
.TP
.B \fB%C\fP
delivery datetime
.TP
.B \fB%e\fP
delivery status on receiving or status error on sending
.TP
.B \fB%t\fP
message reference
.TP
.B \fB%d\fP
receiving datetime for received sms
.TP
.B \fB%E\fP
encoded text of SMS
.TP
.B \fB%c\fP
SMS coding (ie 8bit or UnicodeNoCompression)
.TP
.B \fB%F\fP
sms centre number
.TP
.B \fB%u\fP
UDH header
.TP
.B \fB%x\fP
class
.TP
.B \fB%T\fP
decoded SMS text
.TP
.B \fB%A\fP
CreatorID of SMS (sending sms)
.TP
.B \fB%V\fP
relative validity
.UNINDENT
.IP [1] 5
Sender number for received messages (insert to inbox or delivery notifications), destination otherwise.
.SH CONFIGURABLE QUERIES
.sp
All configurable queries can be set in \fB[sql]\fP section. Sequence of rows in selects are mandatory.
.sp
All default queries noted here are noted for MySQL. Actual time and time addition
are selected for default queries during initialization.
.INDENT 0.0
.TP
.B delete_phone
Deletes phone from database.
.sp
Default value:
.INDENT 7.0
.INDENT 3.5
.sp
.nf
.ft C
DELETE FROM phones WHERE IMEI = %I
.ft P
.fi
.UNINDENT
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B insert_phone
Inserts phone to database.
.sp
Default value:
.INDENT 7.0
.INDENT 3.5
.sp
.nf
.ft C
INSERT INTO phones (IMEI, ID, Send, Receive, InsertIntoDB, TimeOut, Client, Battery, Signal)
VALUES (%I, %P, %1, %2, NOW(), (NOW() + INTERVAL 10 SECOND) + 0, %N, \-1, \-1)
.ft P
.fi
.UNINDENT
.UNINDENT
.sp
Query specific parameters:
.INDENT 7.0
.TP
.B \fB%1\fP
enable send (yes or no) \- configuration option Send
.TP
.B \fB%2\fP
enable receive (yes or no)  \- configuration option Receive
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B save_inbox_sms_select
Select message for update delivery status.
.sp
Default value:
.INDENT 7.0
.INDENT 3.5
.sp
.nf
.ft C
SELECT ID, Status, SendingDateTime, DeliveryDateTime, SMSCNumber FROM sentitems
WHERE DeliveryDateTime IS NULL AND SenderID = %P AND TPMR = %t AND DestinationNumber = %R
.ft P
.fi
.UNINDENT
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B save_inbox_sms_update_delivered
Update message delivery status if message was delivered.
.sp
Default value:
.INDENT 7.0
.INDENT 3.5
.sp
.nf
.ft C
UPDATE sentitems SET DeliveryDateTime = %C, Status = %1, StatusError = %e WHERE ID = %2 AND TPMR = %t
.ft P
.fi
.UNINDENT
.UNINDENT
.sp
Query specific parameters:
.INDENT 7.0
.TP
.B \fB%1\fP
delivery status returned by GSM network
.TP
.B \fB%2\fP
ID of message
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B save_inbox_sms_update
Update message if there is an delivery error.
.sp
Default value:
.INDENT 7.0
.INDENT 3.5
.sp
.nf
.ft C
UPDATE sentitems SET Status = %1, StatusError = %e WHERE ID = %2 AND TPMR = %t
.ft P
.fi
.UNINDENT
.UNINDENT
.sp
Query specific parameters:
.INDENT 7.0
.TP
.B \fB%1\fP
delivery status returned by GSM network
.TP
.B \fB%2\fP
ID of message
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B save_inbox_sms_insert
Insert received message.
.sp
Default value:
.INDENT 7.0
.INDENT 3.5
.sp
.nf
.ft C
INSERT INTO inbox (ReceivingDateTime, Text, SenderNumber, Coding, SMSCNumber, UDH,
Class, TextDecoded, RecipientID) VALUES (%d, %E, %R, %c, %F, %u, %x, %T, %P)
.ft P
.fi
.UNINDENT
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B update_received
Update statistics after receiving message.
.sp
Default value:
.INDENT 7.0
.INDENT 3.5
.sp
.nf
.ft C
UPDATE phones SET Received = Received + 1 WHERE IMEI = %I
.ft P
.fi
.UNINDENT
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B refresh_send_status
Update messages in outbox.
.sp
Default value:
.INDENT 7.0
.INDENT 3.5
.sp
.nf
.ft C
UPDATE outbox SET SendingTimeOut = (NOW() + INTERVAL 60 SECOND) + 0
WHERE ID = %1 AND (SendingTimeOut < NOW() OR SendingTimeOut IS NULL)
.ft P
.fi
.UNINDENT
.UNINDENT
.sp
The default query calculates sending timeout based on \fBLoopSleep\fP
value.
.sp
Query specific parameters:
.INDENT 7.0
.TP
.B \fB%1\fP
ID of message
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B find_outbox_sms_id
Find sms messages for sending.
.sp
Default value:
.INDENT 7.0
.INDENT 3.5
.sp
.nf
.ft C
SELECT ID, InsertIntoDB, SendingDateTime, SenderID FROM outbox
WHERE SendingDateTime < NOW() AND SendingTimeOut <  NOW() AND
SendBefore >= CURTIME() AND SendAfter <= CURTIME() AND
( SenderID is NULL OR SenderID = \(aq\(aq OR SenderID = %P ) ORDER BY InsertIntoDB ASC LIMIT %1
.ft P
.fi
.UNINDENT
.UNINDENT
.sp
Query specific parameters:
.INDENT 7.0
.TP
.B \fB%1\fP
limit of sms messages sended in one walk in loop
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B find_outbox_body
Select body of message.
.sp
Default value:
.INDENT 7.0
.INDENT 3.5
.sp
.nf
.ft C
SELECT Text, Coding, UDH, Class, TextDecoded, ID, DestinationNumber, MultiPart,
RelativeValidity, DeliveryReport, CreatorID FROM outbox WHERE ID=%1
.ft P
.fi
.UNINDENT
.UNINDENT
.sp
Query specific parameters:
.INDENT 7.0
.TP
.B \fB%1\fP
ID of message
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B find_outbox_multipart
Select remaining parts of sms message.
.sp
Default value:
.INDENT 7.0
.INDENT 3.5
.sp
.nf
.ft C
SELECT Text, Coding, UDH, Class, TextDecoded, ID, SequencePosition
FROM outbox_multipart WHERE ID=%1 AND SequencePosition=%2
.ft P
.fi
.UNINDENT
.UNINDENT
.sp
Query specific parameters:
.INDENT 7.0
.TP
.B \fB%1\fP
ID of message
.TP
.B \fB%2\fP
Number of multipart message
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B delete_outbox
Remove messages from outbox after threir successful send.
.sp
Default value:
.INDENT 7.0
.INDENT 3.5
.sp
.nf
.ft C
DELETE FROM outbox WHERE ID=%1
.ft P
.fi
.UNINDENT
.UNINDENT
.sp
Query specific parameters:
.INDENT 7.0
.TP
.B \fB%1\fP
ID of message
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B delete_outbox_multipart
Remove messages from outbox_multipart after threir successful send.
.sp
Default value:
.INDENT 7.0
.INDENT 3.5
.sp
.nf
.ft C
DELETE FROM outbox_multipart WHERE ID=%1
.ft P
.fi
.UNINDENT
.UNINDENT
.sp
Query specific parameters:
.INDENT 7.0
.TP
.B \fB%1\fP
ID of message
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B create_outbox
Create message (insert to outbox).
.sp
Default value:
.INDENT 7.0
.INDENT 3.5
.sp
.nf
.ft C
INSERT INTO outbox (CreatorID, SenderID, DeliveryReport, MultiPart,
InsertIntoDB, Text, DestinationNumber, RelativeValidity, Coding, UDH, Class,
TextDecoded) VALUES (%1, %P, %2, %3, NOW(), %E, %R, %V, %c, %u, %x, %T)
.ft P
.fi
.UNINDENT
.UNINDENT
.sp
Query specific parameters:
.INDENT 7.0
.TP
.B \fB%1\fP
creator of message
.TP
.B \fB%2\fP
delivery status report \- yes/default
.TP
.B \fB%3\fP
multipart \- FALSE/TRUE
.TP
.B \fB%4\fP
Part (part number)
.TP
.B \fB%5\fP
ID of message
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B create_outbox_multipart
Create message remaining parts.
.sp
Default value:
.INDENT 7.0
.INDENT 3.5
.sp
.nf
.ft C
INSERT INTO outbox_multipart (SequencePosition, Text, Coding, UDH, Class,
TextDecoded, ID) VALUES (%4, %E, %c, %u, %x, %T, %5)
.ft P
.fi
.UNINDENT
.UNINDENT
.sp
Query specific parameters:
.INDENT 7.0
.TP
.B \fB%1\fP
creator of message
.TP
.B \fB%2\fP
delivery status report \- yes/default
.TP
.B \fB%3\fP
multipart \- FALSE/TRUE
.TP
.B \fB%4\fP
Part (part number)
.TP
.B \fB%5\fP
ID of message
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B add_sent_info
Insert to sentitems.
.sp
Default value:
.INDENT 7.0
.INDENT 3.5
.sp
.nf
.ft C
INSERT INTO sentitems (CreatorID,ID,SequencePosition,Status,SendingDateTime,
SMSCNumber, TPMR, SenderID,Text,DestinationNumber,Coding,UDH,Class,TextDecoded,
InsertIntoDB,RelativeValidity)
VALUES (%A, %1, %2, %3, NOW(), %F, %4, %P, %E, %R, %c, %u, %x, %T, %5, %V)
.ft P
.fi
.UNINDENT
.UNINDENT
.sp
Query specific parameters:
.INDENT 7.0
.TP
.B \fB%1\fP
ID of sms message
.TP
.B \fB%2\fP
part number (for multipart sms)
.TP
.B \fB%3\fP
message state (SendingError, Error, SendingOK, SendingOKNoReport)
.TP
.B \fB%4\fP
message reference (TPMR)
.TP
.B \fB%5\fP
time when inserted in db
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B update_sent
Update sent statistics after sending message.
.sp
Default value:
.INDENT 7.0
.INDENT 3.5
.sp
.nf
.ft C
UPDATE phones SET Sent= Sent + 1 WHERE IMEI = %I
.ft P
.fi
.UNINDENT
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B refresh_phone_status
Update phone status (battery, signal).
.sp
Default value:
.INDENT 7.0
.INDENT 3.5
.sp
.nf
.ft C
UPDATE phones SET TimeOut= (NOW() + INTERVAL 10 SECOND) + 0,
Battery = %1, Signal = %2 WHERE IMEI = %I
.ft P
.fi
.UNINDENT
.UNINDENT
.sp
Query specific parameters:
.INDENT 7.0
.TP
.B \fB%1\fP
battery percent
.TP
.B \fB%2\fP
signal percent
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B update_retries
Update number of retries for outbox message. The interval can be configured
by \fBRetryTimeout\fP\&.
.INDENT 7.0
.INDENT 3.5
.sp
.nf
.ft C
UPDATE outbox SET SendngTimeOut = (NOW() + INTERVAL 600 SECOND) + 0,
Retries = %2 WHERE ID = %1
.ft P
.fi
.UNINDENT
.UNINDENT
.sp
Query specific parameters:
.INDENT 7.0
.TP
.B \fB%1\fP
message ID
.TP
.B \fB%2\fP
number of retries
.UNINDENT
.UNINDENT
.SH AUTHOR
Michal Čihař <michal@cihar.com>
.SH COPYRIGHT
2009-2015, Michal Čihař <michal@cihar.com>
.\" Generated by docutils manpage writer.
.
